package com.huoyun.user.action;

import com.huoyun.base.action.BaseAction;
import com.huoyun.base.bean.Page;
import com.huoyun.user.service.evt.GetComplaintsByUserIdEvt;
import com.huoyun.user.bean.Complaint;
import com.huoyun.user.service.ComplaintService;

public class ComplaintAction extends BaseAction{
	private Page complaintPage;
	public Complaint complaintObj;
	private ComplaintService complaintService;
	private long id;
	
	public Page getComplaintPage() {
		return complaintPage;
	}

	public void setComplaintPage(Page complaintPage) {
		this.complaintPage = complaintPage;
	}

	public Complaint getComplaintObj() {
		return complaintObj;
	}

	public void setComplaintObj(Complaint complaintObj) {
		this.complaintObj = complaintObj;
	}

	public long getId() {
		return id;
	}

	public void setComplaintId(long id) {
		this.id = id;
	}

	public String insertComplaint()
	{
		try
		{
			long id = getLoginUser().getId();
			complaintObj.setComplaintor_id(id);
			complaintObj.setStatus(0);
			//complaint.setAdd_date();
			complaintService.insertComplaint(complaintObj);
		}
		catch(Exception ex)
		{
			return ERROR;
		}
		return SUCCESS;
	}
	
	public Page getCargoPage() {
		return complaintPage;
	}

	public void setCargoPage(Page complaintPage) {
		this.complaintPage = complaintPage;
	}

	public Complaint getComplaint() {
		return complaintObj;
	}

	public void setComplaint(Complaint complaint) {
		this.complaintObj = complaint;
	}

	public ComplaintService getComplaintService() {
		return complaintService;
	}

	public void setComplaintService(ComplaintService complaintService) {
		this.complaintService = complaintService;
	}

	public String updateComplaint()
	{
		try
		{
			complaintService.updateComplaint(complaintObj);
		}
		catch(Exception ex)
		{
			return ERROR;
		}
		
		return SUCCESS;
	}
	
	public String deleteComplaint()
	{
		try
		{
			String strID = getRequest().getParameter("id");
			this.id = Long.parseLong(strID);
			complaintService.deleteComplaint(id);
		}
		catch(Exception ex)
		{
			return ERROR;
		}
		return SUCCESS;
	}
	
	public String getComplaintById()
	{
		try
		{
			String strID = getRequest().getParameter("id");
			this.id = Long.parseLong(strID);
			complaintObj = complaintService.getComplaintById(id);
		}
		catch(Exception ex)
		{
			return ERROR;
		}
		
		return SUCCESS;
	}
	
	public String preEditComplaint()
	{
		try
		{
			String strID = getRequest().getParameter("id");
			this.id = Long.parseLong(strID);
			complaintObj = complaintService.getComplaintById(id);
		}
		catch(Exception ex)
		{
			return ERROR;
		}
		
		return SUCCESS;
	}
	
	public String preAddComplaint()
	{
		return SUCCESS;
	}
	
	public String preViewComplaint()
	{
		return SUCCESS;
	}
	
	public String complaintList()
	{
		try
		{
			GetComplaintsByUserIdEvt evt = new GetComplaintsByUserIdEvt();
			evt.setUserId(getLoginUser().getId());
			evt.setPageNo(pageNo);
			evt.setPageCount(PAGE_COUNT);
			
			complaintPage = complaintService.getComplaintsByUserId(evt);
		}
		catch(Exception ex)
		{
			ex.fillInStackTrace();
		}
		return SUCCESS;
	}
}
